local skel = fk.CreateSkill {
  name = "emo__kongti",
}

skel:addEffect(fk.RoundStart, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name) and not player:isNude()
  end,
  on_cost = function (self, event, target, player, data)
    if event == fk.TurnStart then return true end
    local room = player.room
    local x = room:getBanner("RoundCount")
    local ids = table.filter(player:getCardIds("he"), function(id) return not player:prohibitDiscard(Fk:getCardById(id)) end)
    local tos, cards = room:askToChooseCardsAndPlayers(player, {
      min_card_num = x, max_card_num = x, pattern = tostring(Exppattern{ id = ids }),
      min_num = 1, max_num = x, targets = room:getOtherPlayers(player),
      skill_name = skel.name, prompt = "#emo__kongti-invoke:::"..x,
    })
    if #tos > 0 and #cards == x then
      room:sortByAction(tos)
      event:setCostData(self, {tos = tos, cards = cards})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local tos, cards = event:getCostData(self).tos, event:getCostData(self).cards
    room:setPlayerMark(player, "emo__kongti-round", table.map(tos, Util.IdMapper))
    room:throwCard(cards, skel.name, player, player)
    for _, to in ipairs(tos) do
      if not to.dead then
        room:damage { from = player, to = to, damage = 1, skillName = skel.name, damageType = fk.FireDamage }
      end
    end
  end,
})

skel:addEffect(fk.TurnStart, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name) and table.contains(player:getTableMark("emo__kongti-round"), target.id)
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:doIndicate(player, {target})
    local skill = Fk.skills["emo__chaofeng"]
    if skill and skill:isInstanceOf(ActiveSkill) then
      ---@cast skill ActiveSkill
      skill:onUse(room, SkillUseData:new {
        from = player,
        cards = {},
        tos = {},
      })
    end
  end,
})

Fk:loadTranslationTable{
  ["emo__kongti"] = "空啼",
  [":emo__kongti"] = "每轮开始时，你可以弃置X张牌，对至多X名其他角色各造成1点火焰伤害，且本轮中这些角色的回合开始时，你发动一次〖朝凤〗（X为本轮轮数）。",
  ["#emo__kongti-invoke"] = "空啼：你可弃置 %arg 张牌，对至多 %arg 名其他角色各造成1点火焰伤害",
}


return skel
